package com.core.nio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * Created with IntelliJ IDEA.
 * User: xf
 * Date: 2016/4/23
 * Time: 0:13
 * To change this template use Editor | File and Code Templates.
 */
public class Client {

    public static void main(String[] args) {
        String msg = "client data";
        try {
            Socket socket = new Socket("127.0.0.1", 8888);
            PrintWriter pw = new PrintWriter(socket.getOutputStream());
            BufferedReader is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            pw.println(msg);
            pw.flush();
            String line = is.readLine();
            System.out.println("received from server:" + line);
            pw.close();
            is.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
